package com.victor.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.victor.entity.Administrator;
import com.victor.entity.step.Schedule;
import com.victor.entity.step.StepDetails;
@Mapper
public interface AdministratorDao {
	/**
	 * 删除管理员
	 * @param ids
	 * @return
	 */
    boolean deleteByPrimaryKey(int[] ids);

    int insert(Administrator record);
    /**
     * 添加管理员
     * @param record
     * @return
     */
    boolean insertSelective(Administrator record);
    /**
     * 根据id查询
     * @param administrator
     * @return
     */
    Administrator selectByPrimaryKey(Administrator administrator);

    boolean updateByPrimaryKeySelective(Administrator record);

    int updateByPrimaryKey(Administrator record);
    /**
     * 查询全部管理员
     * @return
     */
	List<Administrator> selALL();
	/**
	 * 搜索
	 * @param search
	 * @return
	 */
	List<Administrator> selBySearch(String search);
	/**
	 * 根据时间搜索
	 * @param start
	 * @param end
	 * @return
	 */
	List<Administrator> selByTime(String start, String end);
	/**
	 * 根据openid查询
	 * @param openId
	 * @return
	 */
	@Select({"select * from administrator where openid=#{openid}"})
	Administrator selByOpenid(String openId);
	/**
	 * 根据电话查询
	 * @param phone
	 * @return
	 */
	@Select({"select * from administrator where a_username=#{a_username}"})
	Administrator selByPhone(String a_username);
	
	/**
	 * 	查询审批流程是否用到此员工
	 * @param id
	 * @return
	 */
	@Select({"select * from jm_step_details where empid=#{id}"})
	List<StepDetails> selectStepDetails(String id);

	/**
	 * 	删除此员工工作流程
	 * @param id
	 * @return
	 */
	@Delete({"delete from jm_step_details where sd_id=#{sd_id}"})
	boolean delstepDetails(Integer sd_id);

	/**
	 * 	查询此模板下所有流程表
	 * @param id
	 * @return
	 */
	@Select({" select * from jm_step_details where s_id=#{s_id} and position>#{position}"})
	List<StepDetails> selectStepDetailsByS_id(Integer s_id,Integer position);

	/**
	 * 	修改其后全部流程向前挪动一位
	 * @param sd_id
	 * @return
	 */
	@Update({"update jm_step_details set position=#{position} where sd_id=#{sd_id}  "})
	boolean updatePosition(Integer sd_id,Integer position);

	/**
	 * 	查询进度中是否用到此员工
	 * @param sd_id
	 * @param position
	 * @return
	 */
	@Select({" select * from jm_schedule where sp_empid=#{id} "})
	List<Schedule> selectSchedules(String id);

	/**
	 * 	删除该员工审核进度
	 * @param id
	 * @return
	 */
	@Delete({" delete from jm_schedule where id=#{id} "})
	boolean delSchedules(Integer id);

	/**
	 * 	查询该模板下审批进度
	 * @param s_id
	 * @param sp_sequence
	 * @return
	 */
	@Select({" select * from jm_schedule where s_id=#{s_id} and sp_sequence+0 > #{sp_sequence}"})
	List<Schedule> selectScheduleByS_id(String s_id,Integer sp_sequence);

	/**
	 * 	修改审批进度
	 * @param id
	 * @param sp_sequence
	 * @return
	 */
	boolean updateScheduleById(Schedule schedule);
}